home *** CD-ROM | disk | FTP | other *** search
- Path: in2.uu.net!van-bc!uniserve!usenet
- From: nowher@anyplace.com (Chris)
- Newsgroups: comp.lang.c++
- Subject: Re: Help! I am baffled! (newbie) - problem.txt [1/1]
- Date: 8 Feb 1996 06:09:50 GMT
- Organization: UNIServe Online
- Distribution: world
- Message-ID: <4fc43e$cj8@atlas.uniserve.com>
- References: <4euosb$qnj@atlas.uniserve.com> <4f8kvg$ffl@sam.inforamp.net>
- NNTP-Posting-Host: van0217.tvs.net
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.99.2
-
- In article <4f8kvg$ffl@sam.inforamp.net>, rmorin@inforamp.net says...
- >
- >In article <4euosb$qnj@atlas.uniserve.com>, nowher@anyplace.com (Chris)
- wrote:
- >>
- >>TempPart.PartNum = new char[15];
- >>...
- >>TempPart.PartNum=TempStr;
- >>
- >
- >Here's your problem. You allocate a string in the first statement.
- Thus you
- >have a string that is pointed to by TempPart.PartNum. Then you set
- >TempPart.PartNum to TempStr. This does not copy the string, this only
- changes
- >the pointer. Now that first string you pointed to is lost in space and
- you
- >are running into big pointer problems when TempStr get deallocated. To
- copy a
- >string use strcpy or a variant of it. I might be wrong, since you
- included
- >only a portion of the code.
- >
- >Agrivar
-
-
- Thanks for the tip! I tried it again with
- strcpy(TempPart.PartNum,TempStr) and it worked fine.
- I figured it was a problem with the way I was using the pointers, but I
- was looking at it from a different angle.
-
- Thanks again,
- Chris.
-
-